package ca.uvic.group2.api;

import ca.uvic.group2.api.exceptions.*;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.io.IOException;

public interface TransactionServer extends Remote {

    static public String RMI_NAME = "G2TransactionServer";

    long openSession(String username, String password)
        throws SessionExistsException,
               LoginException,
               CommException,
               RemoteException;

    void pingSession(long sessionId) throws SessionNotFoundException,
                                            RemoteException;

    void closeSession(long sessionId) throws SessionNotFoundException,
                                             RemoteException;

    UserInfo getUserInfo(int transId, long sessionId) throws SessionNotFoundException,
                                                             RemoteException;

    String getLogFile(int transId, long sessionId, boolean forUser) throws SessionNotFoundException,
                                                                           RemoteException,
                                                                           IOException;

    Quote quote(int transId, long sessionId, String stockName) throws SessionNotFoundException,
                                                                      CommException,
                                                                      InvalidCommandException,
                                                                      RemoteException;

    PurchaseOrder buy(int transId, long sessionId, String stockName, float dollarAmount)
        throws SessionNotFoundException,
               CommException,
               InvalidCommandException,
               RemoteException;


    Receipt commitBuy(int transId, long sessionId) throws SessionNotFoundException,
                                                          CommException,
                                                          NoPendingCommandException,
                                                          RemoteException;

    PurchaseOrder cancelBuy(int transId, long sessionId) throws SessionNotFoundException,
                                                                CommException,
                                                                NoPendingCommandException,
                                                                RemoteException;

    PurchaseOrder sell(int transId, long sessionId, String stockName, float amount)
        throws SessionNotFoundException,
               CommException,
               InvalidCommandException,
               RemoteException;


    Receipt commitSell(int transId, long sessionId) throws SessionNotFoundException,
                                                           CommException,
                                                           NoPendingCommandException,
                                                           RemoteException;

    PurchaseOrder cancelSell(int transId, long sessionId) throws SessionNotFoundException,
                                                                 CommException,
                                                                 NoPendingCommandException,
                                                                 RemoteException;

    Receipt addFunds(int transId, long sessionId, float amount) throws SessionNotFoundException,
                                                                       CommException,
                                                                       InvalidCommandException,
                                                                       RemoteException;

    Trigger createBuyTrigger(int transId, long sessionId, String stock, float amount) throws RemoteException,
                                                                                             CommException,
                                                                                             InvalidCommandException,
                                                                                             SessionNotFoundException;

    void commitBuyTrigger(int transId, long sessionId, String stock, float stockPrice) throws RemoteException,
                                                                                              CommException,
                                                                                              InvalidCommandException,
                                                                                              SessionNotFoundException;

    void cancelBuyTrigger(int transId, long sessionId, String stock) throws RemoteException,
                                                                            CommException,
                                                                            InvalidCommandException,
                                                                            SessionNotFoundException;

    Trigger createSellTrigger(int transId, long sessionId, String stock, int amount) throws RemoteException,
                                                                                            CommException,
                                                                                            InvalidCommandException,
                                                                                            SessionNotFoundException;

    void commitSellTrigger(int transId, long sessionId, String stock, float stockPrice) throws RemoteException,
                                                                                               CommException,
                                                                                               InvalidCommandException,
                                                                                               SessionNotFoundException;

    void cancelSellTrigger(int transId, long sessionId, String stock) throws RemoteException,
                                                                             CommException,
                                                                             InvalidCommandException,
                                                                             SessionNotFoundException;

    void initSystem() throws RemoteException,
                             CommException,
                             IOException;

}

// Possible errors
//
// Login Failure
// Invalid Session ID
// Communication Failure
// Invalid Operation
//   Insufficient Funds
//   Commit Failure

